package com.ershui.blog.user.service.impl;

import com.ershui.blog.user.domain.LUser;
import com.ershui.blog.user.exception.UserNotExistException;
import com.ershui.blog.user.mapper.LUserMapper;
import com.ershui.blog.user.service.LUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 用户信息service
 * @author  jinbin
 */
@Service
public class LUserServiceImpl implements LUserService {
    @Autowired
    private LUserMapper userMapper;


    @Override
    public int insert(LUser record) {
        int n=userMapper.insert(record);
        return n;
    }

    @Override
    public int insertSelective(LUser record) {
        return userMapper.insertSelective(record);
    }

    /**
     * 根据用户名查询用户信息
     *
     * @param username
     * @return
     */
    @Override
    public LUser selectUserByLoginName(String username,String password) {
        LUser user=userMapper.selectUserByLoginName(username);
        if(user==null){
            throw new UserNotExistException("账号或者密码不正确");
        }else{
            if(!password.equals(user.getUserPwd())){
                throw new UserNotExistException("账号或者密码不正确");
            }
        }
        return user;
    }
}
